﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using AppFx.ComponentModel.Descriptive;

namespace AppFx.Console
{
    public class TypeConsoleCommand : ConsoleCommand
    {
        #region Properties

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new Instance of the TypeConsoleCommand.
        /// </summary>
        /// <param name="name">Name of the Command</param>
        /// <param name="executor">Executor called when executing the command.</param>
        /// <param name="type">Type to fill.</param>
        /// <param name="aliases">Allowed aliases.</param>
        public TypeConsoleCommand(string name, ExecuteDelegate executor, Type type, IEnumerable<string> aliases)
            : base(name, executor, aliases)
        {
            CompiledTypeDescriptionProvider propertyProvider = new CompiledTypeDescriptionProvider();
            var properties = propertyProvider.GetDescriptors(type);

            Parameters = new List<ConsoleParameter>();
            foreach (var property in properties)
            {
                Parameters.Add(new ConsoleParameter(property.Name, null, String.Format("No valid input. Please supply a {0}", property.PropertyType)));
            }
        }

        #endregion

        #region Methods

        #endregion
    }
}
